package com.learning.hadoop.mapreduce.weather;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * ClassName: SortHot
 * Description: 排序
 * Date: 2018/3/25 21:38 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class SortHot extends WritableComparator {

    public SortHot() {
        super(KeyPari.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        KeyPari o1 = (KeyPari) a;
        KeyPari o2 = (KeyPari) b;

        int compare = Integer.compare(o1.getYear(), o2.getYear());
        // 年份升序，气温降序排序
        return compare == 0 ? -Integer.compare(o1.getHot(), o2.getHot()) : compare;
    }
}
